package com.kind.basketball.basketballappactivity.Activity.test;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.kind.basketball.basketballappactivity.R;

/**
 * Created by Administrator on 2016/7/12.
 */
public class ImageAdapter extends BaseAdapter {
    private Context context;
    private int[] mImages = {R.mipmap.guang_xxhdpi,
           R.mipmap.guang_xxhdpi, R.mipmap.guang_xxhdpi };
    private static final int IMAGE_PX_HEIGHT = 198;

    public ImageAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;//实现循环显示
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(context);
        imageView.setImageResource(mImages[position % mImages.length]);
        imageView.setScaleType(ImageView.ScaleType.CENTER);
        imageView.setLayoutParams(new Gallery.LayoutParams(
                Gallery.LayoutParams.FILL_PARENT, IMAGE_PX_HEIGHT));

        RelativeLayout borderImg = new RelativeLayout(context);
        borderImg.setPadding(2, 2, 2, 2);
        borderImg.setBackgroundResource(R.drawable.bg_gallery);//设置ImageView边框
        borderImg.addView(imageView);
        return borderImg;
    }

}